<?php

 header("Content-type:text/html;charset=utf-8");
 $con = mysqli_connect("localhost", 'root', '', 'login');
 mysqli_set_charset($con, "utf8");

session_start();

if(isset($_POST['username'])&&isset($_POST['password'])){
    $username=$_POST['username'];
    $password=$_POST['password'];
    $user=$_POST['user'];

    if($user=='0'){
        $sql="select * from admin where ad_name = '$username' and ad_pwd = '$password';";
        $result = mysqli_query($con,$sql);
        if(mysqli_num_rows($result)!=0){
            header("Location:main.html");
        }
        else{
            echo "<h1>登录失败，用户名或密码错误</h1>";
        }
        
    }else if($user=='1'){
        $sql="select * from user where us_name = '$username' and us_pwd = '$password';";
        $result = mysqli_query($con,$sql);
        if(mysqli_num_rows($result)!=0){
            header("Location:user.html");
        }
        else{
            echo "<h1>登录失败，用户名或密码错误</h1>";
        }
        
    }else{
        echo "<h1>登录失败，用户名不符合规范</h1>";
    }
}else{
    echo "<h1>参数错误，已被服务器记录在案</h1>";
}
mysqli_close($con);
?>